package com.jstyle.jclife.utils;

import android.Manifest;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;

import com.jstyle.jclife.activity.BaseActivity;
import com.jstyle.jclife.activity.OtaActivity;

/**
 * Created by Administrator on 2018/11/2.
 */

public class DfuUtil {

    public static void startDfu(final BaseActivity baseActivity, final String lastPath) {
        PermissionsUtil.requestPermissions(baseActivity, new PermissionsUtil.PermissionListener() {
            @Override
            public void granted(String name) {
                Intent intent = new Intent(baseActivity, OtaActivity.class);
                intent.putExtra(OtaActivity.EXTRA_FILE_PATH, lastPath);
                baseActivity.startActivity(intent);
            }

            @Override
            public void NeverAskAgain() {

            }

            @Override
            public void disallow(String name) {

            }
        }, Manifest.permission.WRITE_EXTERNAL_STORAGE);

    }

    public static void startDfuAndFinish(final AppCompatActivity baseActivity, final String lastPath, final String version) {
        PermissionsUtil.requestPermissions(baseActivity, new PermissionsUtil.PermissionListener() {
            @Override
            public void granted(String name) {
                Intent intent = new Intent(baseActivity, OtaActivity.class);
                intent.putExtra(OtaActivity.EXTRA_FILE_PATH, lastPath);
               SharedPreferenceUtils.setSpString(SharedPreferenceUtils.KEY_fwVersion,version);
                baseActivity.startActivity(intent);
                baseActivity.finish();
            }

            @Override
            public void NeverAskAgain() {

            }

            @Override
            public void disallow(String name) {

            }
        }, Manifest.permission.WRITE_EXTERNAL_STORAGE);

    }

}
